package ru.jexp.rcp.supply.n.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.handlers.HandlerUtil;

public class HandlerCheckAll extends AbstractHandler
{
	
	public static final String ID = "ru.jexp.rcp.supply.n.commands.handlercheckall";
	
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException
	{
		ISelectionProvider provider = HandlerUtil.getActiveSite(event).getSelectionProvider();
		if (provider instanceof CheckboxTreeViewer)
		{
			CheckboxTreeViewer treeViewer = (CheckboxTreeViewer) provider;
			treeViewer.setSubtreeChecked(treeViewer.getInput(), true);
		}
		if (provider instanceof CheckboxTableViewer)
		{
			CheckboxTableViewer tableViewer = (CheckboxTableViewer) provider;
			tableViewer.setAllChecked(true);
		}
		return null;
	}

}
